package com.guli.edu.controller;


import com.guli.commonutils.R;
import com.guli.edu.entity.subject.OneSubject;
import com.guli.edu.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author liuzg
 * @since 2021-03-05
 */
@RestController
@RequestMapping("/edu/subject")
@Api(tags = "课程分类管理")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    // 添加课程分类
    // 获取上传过来文件，把文件内容读取出来
    @ApiOperation(value = "添加课程分类")
    @PostMapping(value = "/addSubject")
    public R addSubject(MultipartFile file) {
        // 上传过来excel文件
        subjectService.saveSubject(file, subjectService);
        return R.ok();
    }

    // 显示课程分类(树形结构)
    @ApiOperation(value = "显示课程分类(树形结构)")
    @GetMapping(value = "/getAllSubject")
    public R getAllSubject() {
        // list 集合泛型是一级分类
        List<OneSubject> list = subjectService.getAllOneTwoSubject();

        return R.ok().data("list",list);
    }

}

